<template>
  <transition name="fade" mode="out-in">
    <div v-if="show">
      <slot></slot>
    </div>
  </transition>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      default: true
    }
  },
  watch: {
    show(val) {
      console.log(val);
    }
  }
}
</script>

<style lang="less" scoped>
// 告诉浏览器需要过渡哪些属性
.fade-enter-active, .fade-leave-active {
  transition: opacity .3s;
}
// 告诉浏览器过渡进入 或者 过渡结束的元素的状态
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
</style>
